$(function () {
  const baseURL = 'http://localhost:8080/api/v1';

  /*  $.ajaxSetup({
     //设置请求头
     //请求发送前
     beforeSend: (xhr) => {
       //获取登录存储的token
       const token = localStorage.getItem('token');
       xhr.setRequestHeader('Authorization', token);
     },
 
     //请求失败
     error: (xhr, status, error) => {
       if (error == 'Forbidden') {
         alert('登录状态失效，请重新登录');
         location.href = 'login.html';
       }
     },
   }); */


  $.ajaxSetup({
    //请求头
    beforeSend: (xhr) => {
      //获取token数据
      const token = localStorage.getItem('token');
      xhr.setRequestHeader('Authorization', token);
    },

    //如果token被清除
    error: (xhr, status, error) => {
      if (error == 'Forbidden') {
        alert('登录状态失败，请重新登录');
        location.href = 'login.html';
      }
    },
  });


  $.ajax({
    method: 'get',
    url: BigNew.user_info,
    data: {},

    success: (res) => {
      //console.log(res);
      /*  const nickname = res.data.nickname;
       const userPic = res.data.userPic; */
      const { nickname, userPic } = res.data; //结构
      $('.user_info span').text(nickname);
      /* $('.user_info img').prop({ src: userPic });
      $('.user_center_link img').prop({ src: userPic }); */
      $('.user_info img,.user_center_link img').prop({ src: userPic })
    },


  })

  /*2.退出登录
          2.1 删除token
          2.2 跳转登录页
           */

  $('.logout').click(() => {
    localStorage.removeItem('token');
    location.href = 'login.html';
  });
  //console.log(BigNew);



  // 左侧点击
  $('.level01').click(function () {
    $(this).addClass('active').siblings().removeClass('active');
    //如果被点击的level01 后面是level02  切换显示level02
    if ($(this).next().hasClass('level02')) {
      $(this).next().stop().slideToggle();
      //找到下面的小图标 切换显示
      $(this).find('.icon-arrowdownl').toggleClass('rotate0');
    } else {
      $('.level02').slideUp();
      $('.level01').find('.icon-arrowdownl').removeClass('rotate0');
      //点击别人 清空.level02还在的全部高亮类名
      $('.level02 li').removeClass('active');
    }
  });
  //显示小列表 的点击效果
  $('.level02 li').click(function () {
    $(this).addClass('active').siblings().removeClass('active');
  });





})